package org.example.servicestudent.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.model.manage.bean.po.Student;
import org.example.servicestudent.mapper.StudentMapper;
import org.example.servicestudent.service.StudentService;
import org.example.servicestudent.util.LocationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-16
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student binding(Long studentId, String unionId, String openId) {
        Student student = studentMapper.selectById(studentId);
        if (student != null) {
            student.setUnionId(unionId);
            student.setOpenId(openId);
            studentMapper.updateById(student);
            return student;
        }
        return null;
    }

    @Override
    public Boolean positioning(String unionId, Double latitude, Double longitude) {
        if(LocationUtil.isWithinRange(latitude, longitude)) {
            studentMapper.updateById(new Student().setUnionId(unionId).setReportCheck(1));
            return true;
        }
        return false;
    }
}
